package cn.school.workmgr.service.impl;

import cn.school.common.utils.SysUserUtils;
import cn.school.workmgr.dao.RecruitBannerDao;
import cn.school.workmgr.entity.RecruitBanner;
import cn.school.workmgr.entity.RecruitMajor;
import cn.school.workmgr.service.RecruitBannerService;
import cn.school.workmgr.vo.RecruitBannerVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

@Service
public class RecruitBannerServiceImpl extends ServiceImpl<RecruitBannerDao, RecruitBanner> implements RecruitBannerService {

    @Override
    public IPage<RecruitBanner> pageList(RecruitBannerVO vo) {
        LambdaQueryWrapper<RecruitBanner> wrapper = new LambdaQueryWrapper<>();

        wrapper.eq(RecruitBanner::getTenantId, SysUserUtils.getSysUser().getTenantId());
        wrapper.orderByAsc(RecruitBanner::getSort);

        return  page(new Page<>(vo.getPageNum(), vo.getPageSize()), wrapper);
    }

    @Override
    public int addOrUpdateMajor(RecruitBanner entity) {
        int num = 0 ;
        if(StringUtils.isEmpty(entity.getId())){
            entity.setStatus("1");
            entity.setCreateBy(SysUserUtils.getSysUser().getUsername());
            entity.setCreateTime(new Date());
            num =this.baseMapper.insert(entity);
        }else{
            entity.setModifyBy(SysUserUtils.getSysUser().getUsername());
            entity.setModifyTime(new Date());
            num =this.baseMapper.updateById(entity);
        }
        return num;
    }

    @Override
    public int deleteById(String id) {
        return this.baseMapper.deleteById(id);
    }

    @Override
    public List<RecruitBanner> bannerList(String tenantId) {
        LambdaQueryWrapper<RecruitBanner> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RecruitBanner::getTenantId,tenantId);
        wrapper.orderByAsc(RecruitBanner::getSort);
        return this.baseMapper.selectList(wrapper);
    }
}
